#!/usr/bin/env python
#
# Copyright 2008 Allen Hutchison (allen@hutchison.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# $URL: http://severedelays.googlecode.com/svn/trunk/appengine/lib/status_value.py $
__version__ = "$Rev: 69 $"
__author__ = "Allen Hutchison (allen@hutchison.org)"

from lib.validators import Validators
from google.appengine.ext import db

class StatusValue(db.Model):
  """Model for status values in the Data Store

  This Model defines all of the data going into the datastore on app engine. It
  enforces some normalization on the data as it's stored through the choices
  attributes.
  """
  update = db.DateTimeProperty(auto_now_add=True)
  name = db.StringProperty(required=True,
                           validator=Validators.validLine)
  status = db.StringProperty(required=True,
                             validator=Validators.validStatus)
  description = db.TextProperty()
  geography = db.StringProperty(required=True,
                                validator=Validators.validGeo)
  network = db.StringProperty(required=True,
                              validator=Validators.validNetwork)
  valueType = db.StringProperty(required=True,
                                validator=Validators.validValueType)

  def getStatus(self):
    return Validators.getStatus(self.status)
  
class CompactStatusValue(StatusValue):
  """Model for compact status values in the Data Store.
  
  This Model is very similar to StatusValue (above) however it has a start
  and stop time defined. This model is meant to represent the entire duration
  of an unchanged status value. So one of these could represent several normal
  StatusValue objects."""
  eventStart = db.DateTimeProperty(required=True)
  eventStop = db.DateTimeProperty(required=True)

  